<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
<div class="page-fixed">
	<button class="btn btn-primary"
		ng-click="showStreamEditor()"
	>+ New Stream</button>
</div>

<p ng-show="streamList._promise.$$state.status !== 1">
	<span class="fa fa-refresh fa-spin"> </span>
	Loading...
</p>

<div class="box box-primary" ng-repeat="stream in streams">
	<div class="box-header with-border">
		<h3 class="box-title">{{stream.tags.streamName}}</h3>
		<div class="box-tools pull-right">
			<button class="btn btn-box-tool" data-widget="collapse">
				<i class="fa fa-minus"></i>
			</button>
			<button class="btn btn-box-tool" ng-click="showStreamEditor(stream)">
				<i class="fa fa-wrench"></i>
			</button>
		</div>
	</div>
	<div class="box-body">
		<div class="inline-group">
			<dl>
				<dt>
					Data Source
				</dt>
				<dd>
					{{stream.tags.dataSource}}
				</dd>
			</dl>
			<dl>
				<dt>
					Stream Name
				</dt>
				<dd>
					{{stream.tags.streamName}}
				</dd>
			</dl>
		</div>
		<div>
			<dl>
				<dt>
					Description
				</dt>
				<dd>
					{{stream.desc}}
				</dd>
			</dl>
		</div>

		<p ng-show="streamSchemaList._promise.$$state.status !== 1">
			<span class="fa fa-refresh fa-spin"> </span>
			Loading...
		</p>

		<div class="list" ng-show="streamSchemaList._promise.$$state.status === 1">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th width="10%">Attribute Name</th>
						<th width="12%">Display Name</th>
						<th width="8%">Type</th>
						<th>Description</th>
					</tr>
				</thead>
				<tbody>
					<tr ng-repeat="meta in stream.metaList">
						<td>{{meta.tags.attrName}}</td>
						<td>{{meta.attrDisplayName}}</td>
						<td><span class="label label-warning">{{meta.attrType}}</span></td>
						<td>{{meta.attrDescription}}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div><!-- /.box-body -->
	<!-- Loading (remove the following to stop the loading)-->
</div>






<!-- Modal: Create / Edit stream -->
<div class="modal fade" id="streamMDL" tabindex="-1" role="dialog">
	<div class="modal-dialog modal-lg" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title">{{!_streamEntity.srcStream ? 'Create' : 'Config'}} Stream</h4>
			</div>
			<div class="modal-body">
				<div class="form-group">
					<label>* Data Source</label>
					<input type="text" class="form-control" placeholder="Data source..." ng-model="_streamEntity.dataSource"
							ng-class="{'has-warning': !_streamEntity.dataSource}" ng-disabled="!!_streamEntity.srcStream" id="dataSource">
				</div>

				<div class="form-group">
					<label>* Stream Name</label>
					<input type="text" class="form-control" placeholder="Stream name..." ng-model="_streamEntity.streamName"
							ng-class="{'has-warning': !_streamEntity.streamName}" ng-disabled="!!_streamEntity.srcStream">
				</div>

				<div class="form-group">
					<label>Description</label>
					<textarea class="form-control" placeholder="Description..." ng-model="_streamEntity.desc"></textarea>
				</div>

				<label>
					* Data Source Schema
				</label>
				<table class="table table-bordered">
					<thead>
						<tr>
							<th width="26"> </th>
							<th width="15%">Attribute Name</th>
							<th width="15%">Display Name</th>
							<th width="15%">Type</th>
							<th>Description</th>
						</tr>
					</thead>
					<tbody>
						<tr ng-repeat="meta in _streamEntity.metaList">
							<td class="input-field text-center">
								<a class="fa fa-trash-o text-danger" ng-click="deleteMeta(meta)"></a>
							</td>
							<td class="input-field"><input type="text" class="form-control" ng-class="{'has-warning': !meta.attrName}" ng-model="meta.attrName" /></td>
							<td class="input-field"><input type="text" class="form-control" ng-model="meta.attrDisplayName" /></td>
							<td class="input-field">
								<select class="form-control" ng-model="meta.attrType">
									<option ng-repeat="type in ['string','bool','long','integer','double','float']">{{type}}</option>
								</select>
							</td>
							<td class="input-field"><input type="text" class="form-control" ng-model="meta.attrDescription" /></td>
						</tr>
					</tbody>
				</table>
				<a ng-click="_streamEntity.metaList.push({attrName: '', attrType: 'string'})">+ Add Schema Item</a>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-danger pull-left" ng-show="_streamEntity.srcStream" ng-click="confirmDeleteStream()" ng-disabled="!checkUpdateStream()">
					Delete
				</button>

				<button type="button" class="btn btn-default" data-dismiss="modal">
					Close
				</button>
				<button type="button" class="btn btn-primary" ng-click="confirmUpateStream()" ng-disabled="!checkUpdateStream()">
					{{!_streamEntity.srcStream ? 'Create' : 'Update'}}
				</button>
			</div>
		</div>
	</div>
</div>